package lrh.hubu.firstproject;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;

public class GridAdapter extends RecyclerView.Adapter<GridAdapter.GridViewHolder>{

    private ArrayList<mydata> List = new ArrayList<mydata>();

    private  Context context;

    public static final int FIRST_STICKY_VIEW = 1;
    public static final int HAS_STICKY_VIEW = 2;
    public static final int NONE_STICKY_VIEW = 3;

    public GridAdapter(Context c) {
        context = c;
    }

    public void setList(ArrayList<mydata> l){
        List = l;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public GridAdapter.GridViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_4, parent, false);
        return new GridViewHolder(view);
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void onBindViewHolder(@NonNull GridAdapter.GridViewHolder holder, int position) {
        holder.t1.setText(List.get(position).getGroup());
        holder.t2.setText(List.get(position).getName());
//        final String content = List.get(position).getName();
//        mydata stickyData = List.get(position);

//        holder.t2.setText(stickyData.getName());

//        if (position == 0) {
//            holder.t1.setVisibility(View.VISIBLE);
//        holder.t1.setText(stickyData.group);
//        holder.itemView.setTag(FIRST_STICKY_VIEW);
//    } else {
//        if (!TextUtils.equals(stickyData.group, List.get(position - 1).group)) {
//            holder.t1.setVisibility(View.VISIBLE);
//            holder.t1.setText(stickyData.group);
//            holder.itemView.setTag(HAS_STICKY_VIEW);
//        } else {
//            holder.t1.setVisibility(View.GONE);
//            holder.itemView.setTag(NONE_STICKY_VIEW);
//        }
//    }
//        holder.itemView.setContentDescription(stickyData.group);
//        holder.itemView.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                Toast.makeText(context, "你点击的是：" + content, Toast.LENGTH_SHORT).show();
//            }
//        });
    }

    @Override
    public int getItemCount() {
        return List.size();
    }

    public static class GridViewHolder extends RecyclerView.ViewHolder {
        TextView t1,t2;
        public GridViewHolder(@NonNull View itemView) {
            super(itemView);
            t1 = itemView.findViewById(R.id.t4_1);
            t2 = itemView.findViewById(R.id.t4_2);
        }
    }
}